using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

using Microsoft.Win32;

namespace ClassBuilderWizard.DefaultPlugins
{
    internal class RegistryHelper
    {
        private RegistryKey LastConnection;

        public RegistryHelper()
        {
            Assembly assm = Assembly.GetExecutingAssembly();
            AssemblyCompanyAttribute comp = (AssemblyCompanyAttribute)assm.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0];
            AssemblyProductAttribute prod = (AssemblyProductAttribute)assm.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0];
            this.LastConnection = Registry.CurrentUser.CreateSubKey(@"Software\" + comp.Company + @"\" + prod.Product);
        }
        /// <summary>
        /// Get the last connection string used by the plugin from the registry
        /// </summary>
        public string GetLastConnection()
        {
            //get the database connection string
            string val = (string)LastConnection.GetValue("LastDbConn", string.Empty);

            return val;
        }
        /// <summary>
        /// Safe the connection string to the registry for later use
        /// </summary>
        public void SaveLastConnection(string conn)
        {
            //save the database connection string
            LastConnection.SetValue("LastDbConn", conn);
        }
    }
}
